package com.raycloud.robot.utils;

import java.util.concurrent.Executors;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ScheduledExecutorService;
import org.slf4j.Logger;
import org.springframework.beans.factory.InitializingBean;

public class ThreadPoolMonitor implements InitializingBean{
    public static final Logger logger;
    public static final ScheduledExecutorService monitorThreadPool;
    @Override
    public void afterPropertiesSet() throws Exception{
        ThreadPoolMonitor.monitorThreadPool.scheduleAtFixedRate(() ->{
            try{
                LogUtils.dubboThreadPoolLog();
            }
            catch(Exception e){
                ThreadPoolMonitor.logger.error("dubbo\u7684\u673a\u5668\u4eba\u7ebf\u7a0b\u6c60\u65e5\u5fd7\u4e0a\u62a5\u51fa\u73b0\u5f02\u5e38",e);
            }
        },0L,30L,TimeUnit.SECONDS);
    }
    static{
        logger=LoggerFactory.getLogger(ThreadPoolMonitor.class);
        monitorThreadPool=Executors.newSingleThreadScheduledExecutor();
    }
}
